Find number of items in enumeration

Is there a function call that can give me the number of options in an enumerated type or do I have to loop through the enumerations to get this?  Here is what I'm trying to do:

 

I have a standard number of user-created enumerated types and am creating a script to make sure that a given module contains these enumerated types and that they contain the same enumerations.  If one or more of the types have fewer enumerations, then the script will display it to the user so they can correct that type.  Those types that have the correct number of enums, the script will loop through the enums to make sure the values match the standard.

 

Chris


chrscote - Tue Dec 12 09:50:06 EST 2017

Re: Find number of items in enumeration
chrscote - Tue Dec 12 12:36:35 EST 2017

Oops, I forgot to include my current code.  Here it is:

string adString;
string sObjTypeEnum [] = { "Text", "Requirement", "Heading", "Figure" };
string sOrientEnum [] = { "Portrait", "Landscape", "Landscape - 11x17" };
string arrTypes [] = {};
int nNumObjType = 4;
int nNumOrient = 3;

AttrType atype;
AttrBaseType atVal;

for adString in skStdAttrDefStrs do {
    numEnums = 0;
    adType = type(current Module, adString);
    if (adType == "Enumeration") {
        aType = find(current Module, adString);
        
        if (adString == "*Object Type") {
            arrTypes = sObjTypeEnum;
            nNumEnums = nNumObjType;
        } else if (adString == "*Orientation") {
            arrTypes = sOrientEnum;
            nNumEnums = nNumOrient;
        }
        if (atype.size != nNumEnums) {
            print atype.name " has wrong number of items.\n";
        } else {
            for n in 0:sizeof(arrTypes)-1 do {      //Error here incorrect arguments for function (find)
                if (!find(atype, arrTypes)) {
                    print atype.name " is missing from " adString "\n";
                }
            }
        }
    }
}

I do have more than the 2 enum arrays I've listed, but I didn't want to make this post longer than necessary to get my point across.  skStdAttrDefStrs  is filled with the standard attribute definitions in another function before this one is called.

 

Chris

Re: Find number of items in enumeration
chrscote - Tue Dec 12 12:55:30 EST 2017

Oops, I forgot to include the code that I'm having issues with.  Here it is:

string sObjTypeEnum [] = { "Text", "Requirement", "Heading", "Figure" };
string sOrientEnum [] = { "Portrait", "Landscape", "Landscape - 11x17" };
int nNumObjType = 8;
int nNumOrient = 3;

void checkEnumTypes() {
    string adString = "";
    string adType = "";
    string arrTypes [] = {};
    
    int numEnums;
    int n = 0;
    AttrBaseType atVal;
    AttrType atype;
    
    for adString in skStdAttrDefStrs do {
        numEnums = 0;
        adType = type(current Module, adString);
        
        if (adType == "Enumeration") {
            atype = find(current Module, adString);
            if (adString=="*Object Type") {
                arrTypes = sObjTypeEnum;
                numEnums = nNumObjType;
            } else if (adString=="*Orientation") {
                arrTypes = sOrientEnum;
                numEnums = nNumOrient;
            }
            if (atype.size != numEnums) {
                print atype.name " has wrong number of items.\n";
            } else {
                for n in 0:sizeof(arrTypes)-1 do {
                    if (!find(atype, arrTypes)) {   //This is the error (incorrect arguments)
                            print atype.name " is missing from " adString "\n";
                    }
                }
            }
        }
    }
}

As an FYI, I do have more than the 2 adString values, but only put in 2 here to shorten this post.  I am just looking for the solution to the problem I'm having with the for-loop.

 

Chris

Re: Find number of items in enumeration
smarti.sj - Thu Dec 14 11:46:35 EST 2017

chrscote - Tue Dec 12 12:55:30 EST 2017

Oops, I forgot to include the code that I'm having issues with.  Here it is:

string sObjTypeEnum [] = { "Text", "Requirement", "Heading", "Figure" };
string sOrientEnum [] = { "Portrait", "Landscape", "Landscape - 11x17" };
int nNumObjType = 8;
int nNumOrient = 3;

void checkEnumTypes() {
    string adString = "";
    string adType = "";
    string arrTypes [] = {};
    
    int numEnums;
    int n = 0;
    AttrBaseType atVal;
    AttrType atype;
    
    for adString in skStdAttrDefStrs do {
        numEnums = 0;
        adType = type(current Module, adString);
        
        if (adType == "Enumeration") {
            atype = find(current Module, adString);
            if (adString=="*Object Type") {
                arrTypes = sObjTypeEnum;
                numEnums = nNumObjType;
            } else if (adString=="*Orientation") {
                arrTypes = sOrientEnum;
                numEnums = nNumOrient;
            }
            if (atype.size != numEnums) {
                print atype.name " has wrong number of items.\n";
            } else {
                for n in 0:sizeof(arrTypes)-1 do {
                    if (!find(atype, arrTypes)) {   //This is the error (incorrect arguments)
                            print atype.name " is missing from " adString "\n";
                    }
                }
            }
        }
    }
}

As an FYI, I do have more than the 2 adString values, but only put in 2 here to shorten this post.  I am just looking for the solution to the problem I'm having with the for-loop.

 

Chris

Hi

 AttrType at.size   should give you the number of elements of an enumerated type.

 

Sara

 

Re: Find number of items in enumeration
chrscote - Thu Dec 14 11:56:15 EST 2017

Thanks, that works great!